package com.yiya.service;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;

import com.yiya.bean.Company;
import com.yiya.bean.ForgetPwd;
import com.yiya.mapper.ForgetPwdMapper;

public class TimeTask {
	@Autowired
	private CompanyService companyService;
	
	@Autowired
	private ForgetPwdMapper forgetPwdMapper;
	
	/**
	 * 处理已过期的公司
	 */
	public void handleExpireCompany(){
		List<Company> companies = companyService.getExpireCompany();
		for(Company c:companies){
			c.setState(0);//将公司状态设置为过期
			companyService.Update(c);
		}
	}
	
	/**
	 * 处理已过期未使用的uuid
	 */
	public void handleExpireUUID(){
		Map<String, Object> param = new HashMap<String, Object>();
		param.put("useStatus", "0");
		param.put("nowTime", new Date());
		List<ForgetPwd> list = forgetPwdMapper.selectExpireRecord(param);
		for(ForgetPwd record:list){
			record.setUseStatus(1);
			forgetPwdMapper.updateByPrimaryKeySelective(record);
		}
	}
}
